/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.far.lib;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Jorge
 */
public class FrmFiltro extends HttpServlet {

    private String _ip = null;
    private int _puerto = 1433;
    private String _db = null;
    private String _usuario = null;
    private String _clave = null;
    
    public void init(ServletConfig config) throws ServletException
    {
        this._ip = config.getServletContext().getInitParameter("_IP");
        this._puerto = Integer.parseInt(config.getServletContext().getInitParameter("_PUERTO"));
        this._db = config.getServletContext().getInitParameter("_DB");
        this._usuario = config.getServletContext().getInitParameter("_USUARIO");
        this._clave = config.getServletContext().getInitParameter("_CLAVE");
    }

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        HttpSession sesion = request.getSession(true);
        String usuario_sesion = (String)sesion.getAttribute("usuario");

        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Expires", "Mon, 01 Jan 2001 00:00:01 GMT");
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Cache-Control", "must-revalidate");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();
        
        int op = Integer.parseInt(request.getParameter("op"));

        BaseDatos objBaseDatos = new BaseDatos(this._ip, this._puerto, this._db, this._usuario, this._clave);
        
        /*ResultSet rsProvedores = objBaseDatos.consulta("select distinct proveedor, proveedor as proveedor1 "
                + "from tbl_auspicio with(nolock) where usuario_creacion='"+usuario_sesion+"' order by proveedor");*/
        
        ResultSet rsPlanes = objBaseDatos.consulta("select distinct id_tipo_plan, tipo_plan from vta_auspicio "
                + "where usuario_creacion='"+usuario_sesion+"' order by tipo_plan");
        try {
            switch(op){
                case 1:
                    out.print("obj»filtro^fun»aus_set_filtrar(0, 'Filtro');aus_auspicio_buscar();^frm»");
                    out.print("<table>");
                    out.print("<tr><td>Filtrar por: "
                            + "<label onclick=\"aus_set_filtrar(0, 'Filtro')\"><input type='radio' id='por0' name='por' value='0' checked />Nro. de auspicio </label>"
                            + "<label onclick=\"aus_set_filtrar(1, 'Filtro')\"><input type='radio' id='por1' name='por' value='1' />Proveedor </label>"
                            + "<label onclick=\"aus_set_filtrar(2, 'Filtro')\"><input type='radio' id='por2' name='por' value='2' />Tipo de plan</label>"
                            + " &nbsp; &nbsp;&nbsp; </td>");
                    out.print("<td><div id=\"axProveedorFiltro\"></div><input type=\"text\" id=\"txt\" class=\"buscar\" style=\"width:325px\" onkeypress=\"_evaluar(event, '0123456789-')\" />"
                            +"<input type=\"text\" id=\"provFiltro\" name=\"provFiltro\" class=\"buscar\" style=\"width:325px\" onkeyup=\"aus_getProveedoresFiltro('filtro', 'Filtro');\" />"
                            //+ DatosDinamicos.combo(rsProvedores, "prov", "", "aus_auspicio_buscar()", "", 355)
                            + DatosDinamicos.combo(rsPlanes, "idTP", "", "aus_auspicio_buscar()", "", 355) + "</td>"
                            + "</tr>");
                    
                    out.print("<tr><td>Estado: <select id=\"est\" style=\"width:300px\" onchange=\"aus_auspicio_buscar()\">" +
                                "<option value=\"1\">Creados</option>" +
                                "<option value=\"2\">Anulados</option>" +
                                "<option value=\"5\">Abiertos</option>" +
                                "<option value=\"3\">Confirmados</option>" +
                                "<option value=\"9\">Cerrados</option>" +
                                "</select></td>");
                    out.print("<td>Per&iacute;odo Desde:<input type=\"text\" id=\"fi\" size=\"8\" onkeypress=\"_evaluar(event, '0123456789/')\" /><input type=\"button\" value=\"...\" onClick=\"SelectorFecha.crear('fi', 'SQL');\" /> &nbsp; "
                            + "Hasta:<input type=\"text\" id=\"ff\" size=\"8\" onkeypress=\"_evaluar(event, '0123456789/')\" /><input type=\"button\" value=\"...\" onClick=\"SelectorFecha.crear('ff', 'SQL');\" /> &nbsp; ");
                    out.print("<input type=\"button\" value=\"Filtrar\" onclick=\"aus_auspicio_buscar()\" /></td></tr>");
                    out.print("</table>");
                break;
                    
                case 2:
                    out.print("obj»filtro^fun»aus_set_filtrar(0, 'Filtro');aus_confirmacion_buscar();^frm»");
                    out.print("<table>");
                    out.print("<tr><td>Filtrar por: "
                            + "<label onclick=\"aus_set_filtrar(0, 'Filtro')\"><input type='radio' id='por0' name='por' value='0' checked />Nro. de auspicio </label>"
                            + "<label onclick=\"aus_set_filtrar(1, 'Filtro')\"><input type='radio' id='por1' name='por' value='1' />Proveedor </label>"
                            + "<label onclick=\"aus_set_filtrar(2, 'Filtro')\"><input type='radio' id='por2' name='por' value='2' />Tipo de plan</label>"
                            + " &nbsp; &nbsp;&nbsp; </td>");
                    out.print("<td><div id=\"axProveedorFiltro\"></div><input type=\"text\" id=\"txt\" class=\"buscar\" style=\"width:325px\" />"
                            +"<input type=\"text\" id=\"provFiltro\" name=\"provFiltro\" class=\"buscar\" style=\"width:325px\" onkeyup=\"aus_getProveedoresFiltro('filtro', 'Filtro');\" />"
                            //+ DatosDinamicos.combo(rsProvedores, "prov", "", "aus_confirmacion_buscar()", "", 355)
                            + DatosDinamicos.combo(rsPlanes, "idTP", "", "aus_confirmacion_buscar()", "", 355)
                            + "</td>");
                    
                    out.print("<td><input type=\"button\" value=\"Filtrar\" onclick=\"aus_confirmacion_buscar()\" /></td></tr>");
                    out.print("</table>");
                break;
                    
                case 3:
                    out.print("obj»filtro^fun»aus_set_filtrar(0, 'Filtro');aus_confirmaciones_ver_buscar();^frm»");
                    out.print("<table>");
                    out.print("<tr><td>Filtrar por: "
                            + "<label onclick=\"aus_set_filtrar(0, 'Filtro')\"><input type='radio' id='por0' name='por' value='0' checked />Nro. de auspicio </label>"
                            + "<label onclick=\"aus_set_filtrar(1, 'Filtro')\"><input type='radio' id='por1' name='por' value='1' />Proveedor </label>"
                            + "<label onclick=\"aus_set_filtrar(2, 'Filtro')\"><input type='radio' id='por2' name='por' value='2' />Tipo de plan</label>"
                            + "<label onclick=\"aus_set_filtrar(3, 'Filtro')\"><input type='radio' id='por3' name='por' value='3' />Tipo de Confirmaci&oacute;n</label>"
                            + " &nbsp; &nbsp;&nbsp; </td>");
                    out.print("<td><div id=\"axProveedorFiltro\"></div><input type=\"text\" id=\"txt\" class=\"buscar\" style=\"width:325px\" />"
                            +"<input type=\"text\" id=\"provFiltro\" name=\"provFiltro\" class=\"buscar\" style=\"width:325px\" onkeyup=\"aus_getProveedoresFiltro('filtro', 'Filtro');\" />"
                            //+ DatosDinamicos.combo(rsProvedores, "prov", "", "aus_confirmaciones_ver_buscar()", "", 355)
                            + DatosDinamicos.combo(rsPlanes, "idTP", "", "aus_confirmaciones_ver_buscar()", "", 355)
                            + "<select id=\"tiConf\" style=\"width:355px\" onchange=\"aus_confirmaciones_ver_buscar()\">" +
                                "<option value=\"m\">Manual</option>" +
                                "<option value=\"a\">Autom&aacute;tica</option>" +
                                "</select>"
                            + "</td>");
                    
                    out.print("<td><input type=\"button\" value=\"Filtrar\" onclick=\"aus_confirmaciones_ver_buscar()\" /></td></tr>");
                    out.print("</table>");
                break;
                    
                case 4:
                    out.print("obj»vta1_html^frm»");
                    out.print("<form onsubmit=\"return aus_reporte_imprimir(this)\" autocomplete=\"off\">");
                    out.print("<table width=\"99%\">");
                    
                    out.print("<tr><td colspan=\"2\"><label><input type='radio' id='z0' name='z' checked value='ConsolidadoAuspicio' />Consolidado de Auspicios</label></td></tr>");
                    
                    out.print("<tr><td colspan=\"2\"><hr /></td></tr>");
                    
                    out.print("<tr><td>Fecha de creaci&oacute;n: </td><td>desde<input type=\"text\" id=\"repFi\" name=\"repFi\" size=\"8\" onkeypress=\"_evaluar(event, '0123456789/')\" /><input type=\"button\" value=\"...\" onClick=\"SelectorFecha.crear('repFi', 'SQL');\" /> &nbsp; "
                            + "hasta<input type=\"text\" id=\"repFf\" name=\"repFf\" size=\"8\" onkeypress=\"_evaluar(event, '0123456789/')\" /><input type=\"button\" value=\"...\" onClick=\"SelectorFecha.crear('repFf', 'SQL');\" /></td></tr>");
                    
                    out.print("<tr><td>Tipo de plan: </td><td>"+ DatosDinamicos.combo(rsPlanes, "repIdTP", "", "", "Todos", 355) + "</td></tr>");
                    
                    out.print("<tr><td>Estado: </td><td><select id=\"repEst\" name=\"repEst\" style=\"width:355px\">" +
                                "<option value=\"\">Todos</option>" +
                                "<option value=\"1\">Creados</option>" +
                                "<option value=\"2\">Anulados</option>" +
                                "<option value=\"5\">Abiertos</option>" +
                                "<option value=\"3\">Confirmados</option>" +
                                "<option value=\"9\">Cerrados</option>" +
                                "</select></td></tr>");
                    
                    out.print("<tr><td>Proveedor: </td><td><div id=\"axProveedorReporte\"></div><input type=\"text\" id=\"provReporte\" name=\"provReporte\" class=\"buscar\" style=\"width:325px\" onkeyup=\"aus_getProveedoresFiltro('vta1_html', 'Reporte');\" /></td></tr>");
                    
                    out.print("<tr><td>Nro. de auspicio:</td><td><input type=\"text\" id=\"repNum_aus\" name=\"repNum_aus\" style=\"width:343px\" onkeypress=\"_evaluar(event, '0123456789-')\" /></td></tr>");
                    
                    out.print("<tr><td colspan=\"2\"><hr /></td></tr>");
                    
                    out.print("<tr><td><label><input type='radio' id='x0' name='x' value='Pdf' checked /> PDF</label>");
                    out.print("</td><td><label id=\"axX1\"><input type='radio' id='x1' name='x' value='Excel' /> EXCEL</label></td></tr>");
                    
                    out.print("<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Imprimir\" /></td></tr>");
                    
                    out.print("</table>");
                    out.print("</form>");
                break;
                        
            }
        } finally {
            objBaseDatos.cerrar();
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
